package com.education.welco.controller;

import com.education.common.core.BaseController;
import com.education.common.utils.ApiReturnObject;
import com.education.welco.pojo.JrOpinion;
import com.education.welco.service.IJrOpinionService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * 意见反馈 信息操作处理
 *
 * @author d
 * @date 2022-06-28
 */
@RestController
@RequestMapping("/jrOpinion")
public class JrOpinionController extends BaseController {

    @Autowired
    private IJrOpinionService jrOpinionService;


    /**
     * 查询意见反馈列表
     * (用户名|手机号keyWord)
     * 问题类型yjType 产品问题 2功能改进 3其他问题
     * 处理状态handleStatus 处理状态  1已处理  2未处理  3已忽略
     *
     * @param jrOpinion
     * @param pageNum
     * @param pageSize
     * @return
     */
    @GetMapping("/list")
    public ApiReturnObject list(JrOpinion jrOpinion, Integer pageNum, Integer pageSize) {
        if (pageNum != null && pageSize != null) {
            PageHelper.startPage(pageNum, pageSize);
        }
        List<JrOpinion> list = jrOpinionService.selectJrOpinionList(jrOpinion);
        PageInfo pageInfo = new PageInfo<>(list);
        return new ApiReturnObject("200", "查询成功", pageInfo);
    }

    /**
     * 新增保存意见反馈
     */
    @PostMapping("/add")
    public ApiReturnObject addSave(@RequestBody JrOpinion jrOpinion) {
        jrOpinionService.insertJrOpinion(jrOpinion);
        return new ApiReturnObject("200", "添加成功", "");
    }


    /**
     * 详情意见反馈   主键查询id
     */
    @GetMapping("/selectOne")
    public ApiReturnObject selectOne(Integer id) {
        JrOpinion result = jrOpinionService.selectJrOpinionById(id);
        return new ApiReturnObject("200", "查询成功", result);
    }

    /**
     * 修改保存意见反馈
     */
    @PostMapping("/update")
    public ApiReturnObject editSave(@RequestBody JrOpinion jrOpinion) {
        jrOpinionService.updateJrOpinion(jrOpinion);
        return new ApiReturnObject("200", "修改成功", "");
    }

    /**
     * 删除意见反馈
     */
    @PostMapping("/del")
    public ApiReturnObject remove(@RequestBody Map map) {
        jrOpinionService.deleteJrOpinionByIds(map.get("ids").toString());
        return new ApiReturnObject("200", "删除成功", "");
    }
}